$(function() {
	monitorfun();		
})
let cloudMoniterMenuStr = '';
function monitorfun() {
	 
		$.ajax({
			type : 'post',
			url : ctx+'/engineer/monitor/topbanner',
			success : function(data) {
				if(data.sysResources!=null){
					if(data.sysResources.length > 0){
						
						renderCloudMoniter(data.id, data.sysResources);
						$("#moniterIframe").html(cloudMoniterMenuStr);
					}else{
						$(".moniter").hide();
					}
				}
				function renderCloudMoniter(id, arry) {
					console.log(arry);
				  let childArry = GetParentArry(id, arry);
				  if(childArry.length > 0) {
				      for(let i = 0; i < childArry.length; i++) {
				          cloudMoniterMenuStr += '<li class="dropdown-user">';
				          cloudMoniterMenuStr += '<a href="'+ctx+'/engineer/monitor/main?id='+childArry[i].id+'"'; 

				          if(childArry[i].url == ""){
				        	  cloudMoniterMenuStr += 'data-toggle="dropdown"';
				          }
				          cloudMoniterMenuStr += '>'+childArry[i].title;
				          if(GetParentArry(childArry[i].id, arry).length !== 0) {
				              cloudMoniterMenuStr += '<span class="caret"></span></a><ul class="moniter-iframe childMenu dropdown-menu dropdown-menu-right">';
				              renderCloudMoniter(childArry[i].id, arry);
				              cloudMoniterMenuStr += '</ul>';
				          } else {
				              cloudMoniterMenuStr += '</a>';
				              renderCloudMoniter(childArry[i].id, arry);
				          }
				          cloudMoniterMenuStr += '</li>'
				      }
				  }
				}
				
				function GetParentArry(id, arr) {
					  let newArry = [];
					  for(let i = 0; i < arr.length; i++) {
					      if(arr[i].parentId === id) {
					          newArry.push(arr[i]);
					      }
					  }
					  return newArry;
					}
			}
		})
	}
	
